import QtQuick 2.3
import QtQuick.Controls 1.4

import "../../js/UI.js" as Style

Rectangle {
    id: container
    property int switchValue: m_lineValue*0.6
    width: switchValue*1.8; height: switchValue
    radius: switchValue
    property bool checkStatus: false;

    //value = -1,表示关闭状态，value = 0,表示开启状态
    signal checkChangeSignal(int isvalue);
    property var rectxValue: ;

    Rectangle{
        width: switchValue*1.8; height: switchValue
        color: rect.x<switchValue*0.5? "#e6e6e6":Style.textCommonColor
        //opacity: rect.x === switchValue*0.05||rect.x === container.width - rect.width-switchValue*0.05?1:0.5
        radius: switchValue
        MouseArea{
            anchors.fill: parent
            onClicked:{
                rect.x<switchValue*0.5?(rect.x=container.width - rect.width-switchValue*0.05):rect.x=switchValue*0.05
                if(rectxValue !== rect.x)  {
                    rect.x===switchValue*0.05?checkChangeSignal(-1):checkChangeSignal(0);
                }
            }
            onPressed: rectxValue = rect.x
        }
    }


    Rectangle {
        anchors.verticalCenter: parent.verticalCenter
        id: rect
        width: switchValue*0.9; height: switchValue*0.9
        color: "#ffffff"
        radius: switchValue*0.9
        x: checkStatus?container.width - rect.width-switchValue*0.05:switchValue*0.05

        MouseArea {
            anchors.fill: parent

            drag.target: rect
            drag.axis: Drag.XAxis
            drag.minimumX: switchValue*0.05
            drag.maximumX: container.width - rect.width-switchValue*0.05
            onPressed: rectxValue = rect.x
            onReleased: {
                if(rect.x<switchValue*0.5)  rect.x=switchValue*0.05
                else rect.x=container.width - rect.width-switchValue*0.05
                if(rectxValue !== rect.x)  {
                    rect.x===switchValue*0.05?checkChangeSignal(-1):checkChangeSignal(0);
                }
            }
            onClicked: {
                rect.x<switchValue*0.5?(rect.x=container.width - rect.width-switchValue*0.05):rect.x=switchValue*0.05
                if(rectxValue !== rect.x)  {
                    rect.x===switchValue*0.05?checkChangeSignal(-1):checkChangeSignal(0);
                }
            }
        }
    }


}

